<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Login extends CI_Controller {

    public function __construct() {
        parent::__construct();
        session_start();
        $this->load->model('usuariosM');
    }

    public function index() {
        $data = array();
        $this->loadData($data);
        //  var_dump($data);
        $this->load->view('admin/templates/header', $data);
        $this->load->view('admin/loginV');
        $this->load->view('admin/templates/footer');
    }

    private function loadData(&$data) {
        $data['tab'] = "login";
    }

    public function validarDatos() {

        if (!empty($_POST)) {
            $valido = true;
            $this->escapar($_POST);
            $user = $this->usuariosM->getSuperAdministrador($_POST['usuario'], $_POST['pass']);
            if (sizeof($user) == 1) {
                $_SESSION['usuario']['rol'] = 'superadministrador';                
            } else {
                $valido = false;
            }

            if ($valido) {
                header("Location:../inicio");
            } else {
                header("Location:../admin");
            }
        }
    }

}
